package com.android.fragmentdemo
import android.app.Application
import com.android.fragmentdemo.roomdb.RoomDBEntrance
import com.android.fragmentdemo.util.SharedPreferencesUtil
import com.tencent.bugly.crashreport.CrashReport

class DefApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        RoomDBEntrance.init(applicationContext)
        SharedPreferencesUtil.init(applicationContext)
    }

    private fun initBugly() {
        val strategy = CrashReport.UserStrategy(this)
        strategy.setCrashHandleCallback(object : CrashReport.CrashHandleCallback() {
            override fun onCrashHandleStart(
                crashType: Int,
                errorType: String?,
                errorMessage: String?,
                errorStack: String?
            ): MutableMap<String, String> {
                //出现异常捕获异常后，会回调这个方法，可用于存储一些值。
                return super.onCrashHandleStart(crashType, errorType, errorMessage, errorStack)
            }

            override fun onCrashHandleStart2GetExtraDatas(
                crashType: Int,
                errorType: String?,
                errorMessage: String?,
                errorStack: String?
            ): ByteArray {
                //return super.onCrashHandleStart2GetExtraDatas(crashType, errorType, errorMessage, errorStack)
                //出现异常捕获异常后，会回调这个方法，可用于存储一些值。
                return ByteArray(128)
            }
        })
        //初始化 第二个参数传bugId
        CrashReport.initCrashReport(this, "", BuildConfig.IN_DEBUG_MODE, strategy)
        //设置设备id
        CrashReport.setDeviceId(this, "")
        //设置应用报名
        CrashReport.setAppPackage(this, "com.android.fragmentdemo")
        //开启bugly
        CrashReport.enableBugly(true)
        //设置数据存储路径
        CrashReport.setDumpFilePath(this, "")
        //设置服务器url
        CrashReport.setServerUrl("")
    }
}